﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UCLibrary.UC
{
    public partial class UCGradient : UserControl
    {
        public UCGradient()
        {
            InitializeComponent();

            //SetStyle(ControlStyles.UserPaint, true);
            //SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            //SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            //SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            //ColorBlend colorBlend = new ColorBlend();
            //colorBlend.Positions = new float[3] { 0f, 0.5f, 1 };
            //colorBlend.Colors = new Color[3]
            //{
            //    Color.Green,
            //    Color.White,
            //    Color.Green
            //};
            //LinearGradientBrush lg = new LinearGradientBrush(new PointF(0, 0), new PointF(0, Height), Color.Green, Color.White);
            //lg.InterpolationColors = colorBlend;
            //g.FillRectangle(lg, this.ClientRectangle);
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(this.ClientRectangle);
            //十字渐变
            //PathGradientBrush pg = new PathGradientBrush(new PointF[]
            //{
            //    new PointF(0,0),
            //    new PointF(Width,0),
            //    new PointF(Width,Height),
            //    new PointF(0,Height)
            //});

            //中心渐变
            PathGradientBrush pg = new PathGradientBrush(path);
            pg.CenterColor = Color.White;
            pg.CenterPoint = new PointF(Width / 2, Height / 2);
            pg.SurroundColors = new Color[]
            {
                Color.Red//, Color.Green, Color.Blue,Color.Orange
            };

            g.FillPath(pg, path);
            ////线性渐变
            //ColorBlend blend = new ColorBlend();
            //blend.Positions = new float[3]
            //{
            //   0, 0.5f, 1
            //};
            //blend.Colors = new Color[3] { Color.Green, Color.White, Color.Black };
            //LinearGradientBrush lg = new LinearGradientBrush(new PointF(0, 0), new PointF(0, Height), Color.Green, Color.White);
            //lg.InterpolationColors = blend;

            //g.FillPath(lg, path);



        }
    }
}
